package edu.wong.pro.serviceImpl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.hibernate.Session;
import org.hibernate.Transaction;

import edu.wong.pro.dao.MemberDAO;
import edu.wong.pro.iservice.ILogin;
import edu.wong.pro.model.Member;
import edu.wong.pro.other.MD5;

public class LoginService implements ILogin{

	@Override
	public String doLogin(String number, String password) {
		// TODO Auto-generated method stub
		HttpSession httpSession = ServletActionContext.getRequest().getSession();
		MemberDAO dao = new MemberDAO();
		Session session = dao.getSession();
		Member member= new Member();
		member.setNumber(number);
		member.setPassword(password);
		//member.setPassword(MD5.getMd5(pwd));
		Transaction transaction = session.beginTransaction();
		List<Member> list = dao.findByExample(member);
		session.close();
		if(list!=null&&list.size()>=1){
			httpSession.setAttribute("isLogin", "ture");
			httpSession.setAttribute("memberID",list.get(0).getMemId());
			httpSession.setAttribute("memname", list.get(0).getMemname());
			if(list.get(0).getEmail()==null)
				return "improve";
			return "ok";
		}else {
			httpSession.setAttribute("isLogin", "false");
			return "no";
		}
		
	}

}
